<template>
  <div>
    <van-nav-bar title="账号登录" left-arrow/>
    <van-form @submit="onSubmit">
      <van-field
        v-model="formLogin.username"
        name="账号"

        placeholder="请输入账号"
        :rules="[{ required: true, message: '用户格式5-8位的字母和数字',pattern:/^[a-zA-Z0-9]{5,8}$/ }]"
      />
      <van-field
        v-model="formLogin.password"
        type="password"
        name="密码"

        placeholder="请输入密码"
        :rules="[{ required: true, message: '密码格式5-12位的字母和数字',pattern: /^[a-zA-Z0-9]{5,12}$/}]"
      />
      <div style="margin: 18px">
        <van-button
        block type="info"
        native-type="submit"
        color="#5fb67f"
        :loading="isLoding"
       :disabled="isLoding"
          >登录</van-button
        >
      </div>
    </van-form>
    <div class="zhuc"
    style="color: #666; font-size: 14px; text-align: center">
      <p>还没有账号？去注册</p>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { Notify } from 'vant'

export default {
  name: 'Login',
  data () {
    return {
      formLogin: {
        username: 'hzhmqd',
        password: '123456'
      },
      isLoding: false
    }
  },
  methods: {
    ...mapActions(['asyncLoginAction']),
    async onSubmit () {
      this.isLoding = true
      try {
        await this.asyncLoginAction(this.formLogin)
        Notify({ type: 'success', message: '登录成功' })
        this.isLoding = false
        this.$router.replace('/layout/home')
      } catch (err) {
        Notify({ type: 'warning', message: '用户名或密码错误' })
        this.isLoding = false
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
